package com.longma.server.controller;


import com.longma.server.entity.InspectionProject;
import com.longma.server.pojo.UserResponseEntity;
import com.longma.server.pojo.dto.InspectionProjectDTO;
import com.longma.server.pojo.dto.InspectionProjectUpdateDTO;
import com.longma.server.service.IInspectionProjectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HAIBO
 * @since 2021-04-28
 */
@RestController
@RequestMapping("/api/inspection-project")
public class InspectionProjectController {
    @Autowired
    IInspectionProjectService iInspectionProjectService;

    @ApiOperation(value = "新增巡視项目")
    @PostMapping("/add")
    public UserResponseEntity<InspectionProject> addInspectionProject(@Valid @RequestBody InspectionProjectDTO addRequestDTO){
        return UserResponseEntity.success(iInspectionProjectService.addInspectionProject(addRequestDTO));
    }

    @ApiOperation(value = "根据巡視記錄id查找巡視项目")
    @PostMapping("/get")
    public UserResponseEntity<List<InspectionProject>> getInspectionProjectByRId(@NotNull(message = "巡視記錄id不能为空")  @RequestParam Integer rid){
        return UserResponseEntity.success(iInspectionProjectService.getInspectionProjectByRecordId(rid));
    }

    @ApiOperation(value = "根据巡检项目id删除巡检项目")
    @PostMapping("/del")
    public UserResponseEntity<Boolean> deleteInspectionProjectById(@NotNull(message = "巡检項目id不能为空")  @RequestParam Integer id){
        return UserResponseEntity.success(iInspectionProjectService.deleteInspectionProjectById(id));
    }

    @ApiOperation(value = "根据巡检项目id列表删除巡检项目")
    @PostMapping("/dellist")
    public UserResponseEntity<Boolean> deleteInspectionProjectByIds(@RequestParam(name="ids") @Size(min = 1,message = "巡检項目id列表不能为空")
                                                                           List<@Valid @NotNull(message = "巡检項目id不能为空") Integer> ids){
        return UserResponseEntity.success(iInspectionProjectService.deleteInspectionProjectByIds(ids));
    }

    @ApiOperation(value = "更新巡检项目")
    @PostMapping("/update")
    public UserResponseEntity<InspectionProject> updateInspectionProjectSetting(@Valid @RequestBody InspectionProjectUpdateDTO updateRequestDTO){
        return UserResponseEntity.success(iInspectionProjectService.updateInspectionProject(updateRequestDTO));
    }
}

